
package com.chessimo.config;


import java.io.File;
import java.io.IOException;

import com.chessimo.main.Chess;
import com.chessimo.util.Utilities;


public class ConfigControl {
    
    
    public static int soundParam;
    public static int timeExercParam;
    public static int whiteBottonParam;
    public static int showInstrParam;
    public static int turnBlackParam;
    public static int boardParam;
    public static int figuresParam;
    public static String user;
    public static String initialDateParam;
    public static String finalDateParam;
    public static int showSolution;
    public static String trainingTatModul;
    public static String trainingEndModul;
    public static String trainingComModul;
    public static String trainingStrModul;
    public static String trainingOpeModul;
    public static int trainingUnitTat;
    public static int trainingUnitEnd;
    public static int trainingUnitCom;
    public static int trainingUnitStr;
    public static int trainingUnitOpe;
    public static int trainingExeTat;
    public static int trainingExeEnd;
    public static int trainingExeCom;
    public static int trainingExeStr;
    public static int trainingExeOpe;
    public static int trainingTimeUnitTat;
    public static int trainingTimeUnitEnd;
    public static int trainingTimeUnitCom;
    public static int trainingTimeUnitStr;
    public static int trainingTimeUnitOpe;
    public static int trainingTimeAvgTat;
    public static int trainingTimeAvgEnd;
    public static int trainingTimeAvgCom;
    public static int trainingTimeAvgStr;
    public static int trainingTimeAvgOpe; 
    
    public static Utilities util = new Utilities();
    
    private File file = new File("config.dat");
    

    public int getSoundParam() {
    	
    	return soundParam;
    	
    }
    
    
    public void incTrainingExe() {
    	
    	String module = Chess.tc.getModule(); 	
    	String moduleType = util.mySubstring(module, 0, 3);
    	
    	if (moduleType.equals("TAT")) {
    		trainingExeTat++;
    	} else if (moduleType.equals("END")) {
    		trainingExeEnd++;
    	} else if (moduleType.equals("COM")) {
    		trainingExeCom++;
    	} else if (moduleType.equals("STR")) {
    		trainingExeStr++;
    	} else if (moduleType.equals("OPE")) {
    		trainingExeOpe++;
    	}
  
    }
    
    
    
    
    
    public void loadConfig() {
        
        
        String[] ret = new String[2];
        String tabParams[] = util.getContentsByLine(file); 
        for (int i=0; i < tabParams.length; i++) {
            
            ret = tabParams[i].split("=");
            
            if (ret[0].equals("user")) {
                user = ret[1];
            } else if (ret[0].equals("sound")) {
                soundParam = Integer.valueOf(ret[1]);    
            } else if (ret[0].equals("timeExerc")) {
                timeExercParam = Integer.valueOf(ret[1]);
            } else if (ret[0].equals("initialDate")) {
                initialDateParam = ret[1];
            } else if (ret[0].equals("finalDate")) {
                finalDateParam = ret[1];
            } else if (ret[0].equals("whiteBotton")) {            
                whiteBottonParam = Integer.valueOf(ret[1]);
            } else if (ret[0].equals("showInstr")) {
                showInstrParam = Integer.valueOf(ret[1]);
            } else if (ret[0].equals("turnBlack")) {            
                turnBlackParam = Integer.valueOf(ret[1]);
            } else if (ret[0].equals("showSolution")) {            
                showSolution = Integer.valueOf(ret[1]);                
            } else if (ret[0].equals("board")) {
                boardParam = Integer.valueOf(ret[1]);
            } else if (ret[0].equals("figures")) {            
                figuresParam = Integer.valueOf(ret[1]);
            } else if (ret[0].equals("trainingTatModul")) {            
                trainingTatModul = ret[1];
            } else if (ret[0].equals("trainingFinModul")) {            
                trainingEndModul = ret[1];                
            } else if (ret[0].equals("trainingComModul")) {            
                trainingComModul = ret[1];
            } else if (ret[0].equals("trainingStrModul")) {            
                trainingStrModul = ret[1];
            } else if (ret[0].equals("trainingOpeModul")) {            
                trainingOpeModul = ret[1];
            } else if (ret[0].equals("trainingUnitTat")) {            
                trainingUnitTat = Integer.valueOf(ret[1]);
            } else if (ret[0].equals("trainingUnitFin")) {            
                trainingUnitEnd = Integer.valueOf(ret[1]);
            } else if (ret[0].equals("trainingUnitCom")) {            
                trainingUnitCom = Integer.valueOf(ret[1]);                
            } else if (ret[0].equals("trainingUnitStr")) {            
                trainingUnitStr = Integer.valueOf(ret[1]);
            } else if (ret[0].equals("trainingUnitOpe")) {            
                trainingUnitOpe = Integer.valueOf(ret[1]);
            } else if (ret[0].equals("trainingExeTat")) {            
                trainingExeTat = Integer.valueOf(ret[1]);
            } else if (ret[0].equals("trainingExeFin")) {            
                trainingExeEnd = Integer.valueOf(ret[1]);
            } else if (ret[0].equals("trainingExeCom")) {            
                trainingExeCom = Integer.valueOf(ret[1]);
            } else if (ret[0].equals("trainingExeStr")) {            
                trainingExeStr = Integer.valueOf(ret[1]);                
            } else if (ret[0].equals("trainingExeOpe")) {            
                trainingExeOpe = Integer.valueOf(ret[1]);
            } else if (ret[0].equals("trainingTimeUnitTat")) {            
                trainingTimeUnitTat = Integer.valueOf(ret[1]);
            } else if (ret[0].equals("trainingTimeUnitFin")) {            
                trainingTimeUnitEnd = Integer.valueOf(ret[1]);
            } else if (ret[0].equals("trainingTimeUnitCom")) {            
                trainingTimeUnitCom = Integer.valueOf(ret[1]);
            } else if (ret[0].equals("trainingTimeUnitStr")) {            
                trainingTimeUnitStr = Integer.valueOf(ret[1]);
            } else if (ret[0].equals("trainingTimeUnitOpe")) {            
                trainingTimeUnitOpe = Integer.valueOf(ret[1]);                
            } else if (ret[0].equals("trainingTimeAvgTat")) {            
                trainingTimeAvgTat = Integer.valueOf(ret[1]);
            } else if (ret[0].equals("trainingTimeAvgFin")) {            
                trainingTimeAvgEnd = Integer.valueOf(ret[1]);
            } else if (ret[0].equals("trainingTimeAvgCom")) {            
                trainingTimeAvgCom = Integer.valueOf(ret[1]);                
            } else if (ret[0].equals("trainingTimeAvgStr")) {            
                trainingTimeAvgStr = Integer.valueOf(ret[1]);
            } else if (ret[0].equals("trainingTimeAvgOpe")) {            
                trainingTimeAvgOpe = Integer.valueOf(ret[1]);   
            }          
            
        }
        
        
    }
    
 
    public void saveConfig() throws IOException {
        
        String[] lines = new String[36];
        
        lines[0] = "user=" + user;
        lines[1] = "sound=" + soundParam;
        lines[2] = "timeExerc=" + timeExercParam;
        lines[3] = "initialDate=" + initialDateParam;
        lines[4] = "finalDate=" + finalDateParam;
        lines[5] = "whiteBotton=" + whiteBottonParam;
        lines[6] = "showInstr=" + showInstrParam;
        lines[7] = "turnBlack=" + turnBlackParam;
        lines[8] = "showSolution=" + showSolution;
        lines[9] = "board=" + boardParam;
        lines[10] = "figures=" + figuresParam;        
        lines[11] = "trainingTatModul=" + trainingTatModul;
        lines[12] = "trainingFinModul=" + trainingEndModul;        
        lines[13] = "trainingComModul=" + trainingComModul;        
        lines[14] = "trainingStrModul=" + trainingStrModul;
        lines[15] = "trainingOpeModul=" + trainingOpeModul;
        lines[16] = "trainingUnitTat=" + trainingUnitTat;        
        lines[17] = "trainingUnitFin=" + trainingUnitEnd;        
        lines[18] = "trainingUnitCom=" + trainingUnitCom;
        lines[19] = "trainingUnitStr=" + trainingUnitStr;
        lines[20] = "trainingUnitOpe=" + trainingUnitOpe;        
        lines[21] = "trainingExeTat=" + trainingExeTat;        
        lines[22] = "trainingExeFin=" + trainingExeEnd;
        lines[23] = "trainingExeCom=" + trainingExeCom;
        lines[24] = "trainingExeStr=" + trainingExeStr;        
        lines[25] = "trainingExeOpe=" + trainingExeOpe;        
        lines[26] = "trainingTimeUnitTat=" + trainingTimeUnitTat;
        lines[27] = "trainingTimeUnitFin=" + trainingTimeUnitEnd;
        lines[28] = "trainingTimeUnitCom=" + trainingTimeUnitCom;        
        lines[29] = "trainingTimeUnitStr=" + trainingTimeUnitStr;        
        lines[30] = "trainingTimeUnitOpe=" + trainingTimeUnitOpe;
        lines[31] = "trainingTimeAvgTat=" + trainingTimeAvgTat;
        lines[32] = "trainingTimeAvgFin=" + trainingTimeAvgEnd;        
        lines[33] = "trainingTimeAvgCom=" + trainingTimeAvgCom;        
        lines[34] = "trainingTimeAvgStr=" + trainingTimeAvgStr;
        lines[35] = "trainingTimeAvgOpe=" + trainingTimeAvgOpe;
        
        util.writeFile(lines, file);
    
    }
  
}
